<template>
  <div class="tab-bar-item" :style="activeStyle" @click="itemClick">
    <slot name="item-icon"></slot>
    <slot name="item-text"></slot>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    path: String,
    activeColor: {
      type: String,
      default: "red"
    }
  },
  data() {
    return {};
  },
  methods: {
    itemClick() {
      //监听路由跳转
      this.$router.replace(this.path);
    }
  },
  computed: {
    isActive() {
      //当前的路由激活 isActive
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      //路由激活样式
      return this.isActive ? { color: this.activeColor } : {};
    }
  }
};
</script>

<style scoped>
/* 在vue中 通过cdn引入阿里巴巴图标库 */
@import url("//at.alicdn.com/t/font_1012213_p42i17qa05.css");

.tab-bar-item {
  flex: 1;
  text-align: center;
  height: 49px;
  line-height: 49px;
}
.tab-bar-item span {
  font-size: 16px;
}
</style>